import axios from "axios";

// 创建axios实例
// 设置请求超时时间

const serve = axios.create({
  baseURL: "/api",
  timeout: 5000,
});

const handleError = async (status: number | undefined) => {
  switch (status) {
    case 500:
      console.error("操作错误");
      break;
    case 403:
      console.error("没有相关权限");
      break;
    default:
      // console.log("成功");
      break;
  }
};

serve.interceptors.response.use((res) => {
  handleError(res.data.code);
  return res;
});

export const ReqGetLocations = async () => serve.post("/getLocations");

export const ReqGetRecent5DayData = async (data: unknown) =>
  serve.post("/getRecent5DayData", data);

export const ReqGetList = async () => serve.post("/getList");
